package com.hfjyz.registration.dao;

import java.util.List;

import com.hfjyz.registration.model.Admin;

public class AdminDaoImpl extends BaseDaoImpl<Admin, String> implements AdminDao {
    protected AdminDaoImpl() {
		super(Admin.class);
	}

    @SuppressWarnings("unchecked")
    @Override
    public Admin get(String adminId) throws Exception {
        List<Admin> adminList = getHibernateTemplate().find(
                "from Admin where administratorId=?", adminId);
        if (adminList == null || adminList.isEmpty()) {
            return null;
        }
        return adminList.get(0);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public Admin getInfoById(Integer id) throws Exception {
        List<Admin> adminList = getHibernateTemplate().find(
                "from Admin where id=?", id);
        if (adminList == null || adminList.isEmpty()) {
            return null;
        }
        return adminList.get(0);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<Admin> filter(String adminId) throws Exception {
        List<Admin> adminList = getHibernateTemplate().find(
                "from Admin where administratorId like ?", "%" + adminId + "%");
        if (adminList == null || adminList.isEmpty()) {
            return null;
        }
        return adminList;
    }

    @Override
    public void update(Admin admin) throws Exception {
        getHibernateTemplate().update(admin);
    }
}
